#![no_std]
#![no_main]
#![feature(llvm_asm)]
#![feature(global_asm)]
#![feature(panic_info_message)]
#![feature(alloc_error_handler)]

#[macro_use]
mod console;
mod lang_items;
mod sbi;
mod loader;
mod trap;
mod syscall;
mod task;
mod config;
mod timer;
mod mm;
mod link_symbols;

use link_symbols::*;

extern crate alloc;
extern crate bitflags; // bitflags 是一个 Rust 中常用来比特标志位的 crate 

global_asm!(include_str!("entry.asm"));
global_asm!(include_str!("link_app.S"));


fn clear_bss() {
    (sbss as usize..ebss as usize).for_each(|addr| {
        unsafe { (addr as *mut u8).write_volatile(0) }
    });
}

#[no_mangle] // Do not change function name
// Rust编译器要找的入口函数
extern "C" fn rust_main() {
    clear_bss();
    mm::init();
    mm::remap_test();
    trap::init();
    trap::enable_timer_interrupt();
    // timer::set_next_trigger();
    task::run_first_task();
    panic!("Unreachable in rust_main!");
}
